package com.borya.listener;

import com.borya.core.TaskExecutorService;
import com.borya.framework.annotation.Autowired;
import com.borya.framework.annotation.Listener;
import com.borya.framework.annotation.Repository;
import com.borya.framework.core.ServerListener;
import com.borya.framework.core.ServerRedisSessionFactory;
import com.borya.framework.core.ServerSqlSessionFactory;
import com.borya.task.AutomaticAudittask;
import com.borya.task.impl.ResourceAutoTask;
import com.borya.task.impl.ShqpTask;
import com.borya.userauth.UserAuthManager;
import com.borya.util.Constant;


@Listener
public class MyServerListener implements ServerListener {

	
	@Repository("/conf/sql.properties")
	private ServerSqlSessionFactory sqlDataSource ;
	@Autowired("taskExecutorService")
	private TaskExecutorService executorService;
	
	@Autowired("resourceAutoTask")
	private ResourceAutoTask resourceAutoTask;

	@Autowired("shqpTask")
	private ShqpTask shqpTask;

	@Repository("/conf/redis.properties")
	private ServerRedisSessionFactory sessionFactory;
	@Override
	public void onStart() {
		System.out.println("Server was started!");
		executorService.process();
		//TMSI 过期时间(小时)
		int tmsi_expired_hour = Constant.TMSI_EXPIRED_HOUR;
		UserAuthManager.getInstance().init(sqlDataSource, tmsi_expired_hour,sessionFactory);
		AutomaticAudittask.getInstance().start();
		resourceAutoTask.start1();
		shqpTask.start1();
	}
	
	@Override
	public void onStop() {
		System.out.println("Http server was destroyed!");
	}
	
}